package com.botarena.server.helper.mappers;

import com.botarena.server.model.Bot;
import com.botarena.shared.BotInfo;
import com.google.appengine.api.datastore.KeyFactory;

public class BotMapper implements ObjectMapper<Bot, BotInfo> {

	@Override
	public BotInfo map(Bot entity) {
		BotInfo botInfo = new BotInfo();
		botInfo.setKey(KeyFactory.keyToString(entity.getKey()));
		botInfo.setName(entity.getName());
		botInfo.setParameters(entity.getParameters());
		botInfo.setSourceCode(entity.getSourceCode());
		botInfo.setCompilationResults(entity.getCompilationResults());
		botInfo.setContestant(entity.isContestant());
		botInfo.setPoints(entity.getRank());
		botInfo.setWins(entity.getWins());
		botInfo.setLosses(entity.getLosses());
		botInfo.setDraws(entity.getDraws());
		
		return botInfo;
	}

	@Override
	public Bot map(BotInfo object) {
		Bot bot = new Bot();
		bot.setKey(KeyFactory.stringToKey(object.getKey()));
		bot.setName(object.getName());
		bot.setParameters(object.getParameters());
		bot.setSourceCode(object.getSourceCode());
		bot.setCompilationResults(object.getCompilationResults());
		bot.setContestant(object.isContestant());
		
		return bot;
	}

}
